<?php
/**
* @package controller
* @file indexController.php
* @date 19.08.2009
* @version 1.0
* @copyright Corjanta
* @author 
* @todo phpDoc comments
*/
     require_once 'Zend/Controller/Action.php';

class profile_indexController extends Cms_Controller_Action
{
	
	public function init()
	{
		//Zend_Layout::getMvcInstance()->setLayoutPath('../app_mvc/index/admin/layouts');
		$this->view->siteTitle = 'Profile';
		
		
	}
	public function indexAction()    
	{ 
		
	}
	public function profileAction()    
	{ 
		  $imagesDir = '/'.$this->CONFIG->path->usersbig;
		  $imagesThumbDir = '/'.$this->CONFIG->path->usersThumb;
		  //echo $imagesThumbDir;exit;
		  $this->view->bigImgPath=$imagesDir;
		   $this->view->thumbImgPath=$imagesThumbDir;
	}
	public function updateProfileAction()
	{
		$memid=$_SESSION["sess_userid"];
		$image=$_POST['image'];
		//echo '<pre>';print_r($_POST);
		$result = Doctrine::getTable('UserDetails')->updateProfileImage($memid,$image);
		$imagesThumbDir = '/'.$this->CONFIG->path->usersThumb;
		$changeImage=$imagesThumbDir.trim($image);
		$_SESSION['sess_photo']=trim($image);
		$jsonData['output'] = $changeImage;
		$this->_helper->json->sendJson($jsonData);
	}
	public function uploadImagesAction()
	  {
	   //echo "uploading";exit;
		  $this->_helper->layout->disableLayout();
		  $this->getHelper('viewRenderer')->setNoRender();
		  $imagesDir = '../'.$this->CONFIG->path->usersbig;
		  $imagesThumbDir = '../'.$this->CONFIG->path->usersThumb;
		if(isset($_FILES['vfile']))
		  {
			 $size=$_FILES['vfile']['size'];
			 //echo $_FILES['vfile']['name'];exit;
		   	 $name = time().'_-_'.$_FILES['vfile']['name'];
			//echo $name;exit;
		 	echo $vidfile = $this->uploadFile($_FILES['vfile']['tmp_name'],$imagesDir,$imagesThumbDir,$name);
		}
	}
		public function uploadFile($tnm,$path,$path1,$fnm)
	 {
	 //echo "hi from  upload file method";
		   $fnm = str_replace(' ','_',$fnm);
		  if(move_uploaded_file($tnm,$path.$fnm))
		    {
			//echo "hi from  upload file method";exit;
			   createthumb($path.$fnm, $path1.$fnm, "150", "150");
			   return $fnm;
		    }
		 else
			return "";
     }
	
	
}
?>
